﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace SusuCMS.Globalization
{
    public class LocalizeDataAnnotationsModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            if (!string.IsNullOrWhiteSpace(metadata.DisplayName))
            {
                metadata.DisplayName = metadata.DisplayName.Localize();
            }

            return metadata;
        }
    }
}
